//
//  AmbitusListCell.m
//  TravelToHelp
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 冯贵宾. All rights reserved.
//

#import "AmbitusListCell.h"

@interface AmbitusListCell ()

@property (nonatomic, strong) UIImageView *photoView;
@property (nonatomic, strong) UILabel *lable;
@property (nonatomic, strong) UIImageView *testView;


@end

@implementation AmbitusListCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    
        
        self.photoView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 170)];
        self.photoView.backgroundColor = [UIColor whiteColor];
        self.photoView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.photoView];
        
        self.lable = [[UILabel alloc] initWithFrame:CGRectMake(0, self.photoView.bottom, kScreenWidth ,50)];
        self.lable.numberOfLines = 0;
        self.lable.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:self.lable];
    }
    return self;
}

- (void)setModel:(AmbitusListModel *)model
{

    [self.photoView sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    self.lable.text = [NSString stringWithFormat:@"%@", model.title];
    // 更改lable的高度
    CGRect newFrame = self.lable.frame;
    newFrame.size.height = [AmbitusListCell cellHeightWithModel:model];
    self.lable.frame = newFrame;
    
    [_testView sd_setImageWithURL:[NSURL URLWithString:model.imageUrl]];
}

+ (CGFloat)cellHeightWithModel:(AmbitusListModel *)model
{
    // 计算字符串高度
    // 字号一定与lable相等
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18] forKey:NSFontAttributeName];
    CGRect lableFrame = [model.title boundingRectWithSize:CGSizeMake(kScreenWidth , 100000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return lableFrame.size.height;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
